<?php
include("common/common.php");
session_start();


$email=$_POST["email"];
$passwd=$_POST["passwd"];
$repasswd=$_POST["repasswd"];
$sex=$_POST["sex"];
$nom=$_POST["nom"];
$prenom=$_POST["prenom"];
$zip=$_POST["zip"];
$tel=$_POST["tel"];


	$data['email'] = $email;
	$data['psword'] = $passwd;
	$data['sex'] = $sex;
	$data['nom'] = $nom;
	$data['prenom'] = $prenom;
	$data['tel'] = $tel;
	$data['zip'] = $zip;
	$data['createtime'] = date("Y-m-d H:i:s");
	$db = Database::obtain(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE);
	$db->connect();
	
	$sql = "SELECT email FROM `user_info`
	WHERE email = '".$email."'";
	$record = $db->query_first($sql);
	if (isset($record['email'])){
		$db->update("user_info", $data,"email='".$email."'");
	}else{ 
		$primary_id = $db->insert("user_info", $data);
	}
	$sql2 = "SELECT email FROM `website`";
	$sitemail = $db->query_first($sql2);
	$db->close();
	setcookie('_user', $email,time()+315360000);
	
	
	//send mail
	$root_path=get_root_path();
	$_lang = null;
	if (is_null($_lang) and isset($_COOKIE['_lang'])){
		$_lang=$_COOKIE['_lang'];
	}else{
		if(is_null($_lang)){
			$_lang = FR;
		}
	}
    $message ='
	<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>kacho-resto</title>
	</head>
	<body>
	<div style="background:url(http://kacho-resto.com/mail/images/mail-bg.png);width:650px;overflow:hidden;position:relative;height:500px">
	<div style="width:650px; background:url(http://kacho-resto.com/mail/images/headBg.png) repeat-x; height:147px; position:absolute; z-index:10">
	<div style="height:147px">
	<h1 style="background:url(http://kacho-resto.com/mail/images/logo.png) no-repeat;width:191px; height:68px; margin:30px 0 0 20px;float:left"></h1>
		
	';
	if($_lang==FR){
		$message .='
		<div style="width:400px; height:45px; overflow:hidden; left:225px; top:45px; position:absolute; font-size:18px; color:#AEAEAE;font-family:Lucida Handwriting"></div>
		<div style="width:400px; height:20px; overflow:hidden; left:225px; position:absolute; font-size:18px; color:#AEAEAE; top:55px;font-family:Lucida Handwriting">';
		$message .= "
		Votre 1er portail franco-arabe de restauration méditerranéenne
		";
	}else{
		$message .='
		<div style="width:400px; height:45px; overflow:hidden; right:25px; top:45px; position:absolute; font-size:18px; color:#AEAEAE;font-family:Lucida Handwriting"></div>
		<div style="width:400px; height:20px; overflow:hidden; text-align:right; right:25px; position:absolute; font-size:18px; color:#AEAEAE; top:55px;font-family:Lucida Handwriting">';
		$message .= "
		موقعكم الوحيد باللغة العربية لعالم المأكولات والضيافة المغربية والشرق أوسطية
		";
	}
     
     $message .='
  </div>
 </div>
</div>
<!--header end of-->


<div style="width:650px; height:500px;filter:progid:DXImageTransform.Microsoft.gradient(startcolorstr=#99ffffff,endcolorstr=#99ffffff); position:absolute; top:147px">
  <h3 style="padding:10px 10px 0 20px;font-size:13px;font-family:Helvetica Neue, regular">';
     if($_lang==FR){
 		$message .='Bonjour ';
 		$message.= $prenom.',</h3>';
     }else{
     	$message.= '،'.$prenom.' ';
     	$message .='مرحباً ';
     	$message.='</h3>';
     }
     
 
  if($_lang==FR){
  	$message.='
  	<p style="padding:0 0 20px 20px;font-size:13px;font-family:Helvetica Neue, regular">';
  $message.=' Votre inscription a bien été enregistrée. Bienvenue dans la communauté KachoResto ! Vous n’avez pas fini d’en profiter !';
  $message.='</p>
  <p style="background-color:#e6e6e6;line-height:30px; padding:5px;text-indent:20px;font-size:13px;color:#4c7b00;font-weight:bold;">';
   }else{
   
   	$message.='<table style="font-size:13px;font-family:Helvetica Neue, regular;margin-left:20px"><tr><td style="margin-left:20px"> .تمَ تسجيل حسابكم لدينا ! kacho-resto.com مرحبا بكم في </tr>';
   	$message.='<tr><td style="margin-left:20px">Vous n’avez pas fini d’en profiter !</tr></table>';
   	$message.='
   	<p style="background-color:#e6e6e6;line-height:30px; padding:5px;text-indent:20px;font-size:13px;color:#4c7b00;font-weight:bold;">';
  }
  
   if($_lang==FR){
   $message.='Vous pouvez dès à présent gérer vos paramètres dans "Mon compte".';
   }else{
   	$message.='."يمكنكم الآن إدارة حسابكم من خلال "حسابي';
   }   
   $message.='</p>   

   
   
   
   <ul style="{width:600px; margin:30px auto">
     <li style="height:48px;margin-top:20px;margin-bottom:10px; font-size:12px"><img style="vertical-align:middle; margin-right:20px" src="http://kacho-resto.com/mail/images/logoPic_1.png" width="83" height="48" />';
     
     if($_lang==FR){
        $message .='A bientôt sur';
        $message .= '<a href="'.$root_path.'" style="color:#333; text-decoration: underline"> kacho-resto.com</a> !</li>';
     }else{
     	$message .= '! <a href="'.$root_path.'" style="color:#333; text-decoration: underline">kacho-resto.com</a> ';
     	$message .='الى اللقاء على';
     	$message .= '</li>';
     }
      
     $message .= '<li style="margin-right:10px;float:right">
         By <a href="'.$root_path.'kac.php?menu=3" style="color:#ff6700; text-decoration: underline">Kachmir Consultancy</a>
     </li>
   </ul>
</div>
<!--regEmail end of-->
</div>
</body>
</html>
';

	$to = $email;
	$subject = "www.kacho-resto.com";
	$from = $sitemail['email'];	
	sendmail($from, $to, $subject, $message);
	
	$lasturl = $_SESSION['currenturl'];
	redirect($lasturl);

?>
